﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BlackStar;
using Microsoft.Xna.Framework.Input;

namespace BlackStarTest
{
    public class AppConsole
    {
        protected Component mainComponent;
        protected Textbox inputText;
        protected Memo outputLabel;

        public AppConsole(GUI g, string componentName)
        {
            mainComponent = g.FindComponent(componentName);
            inputText = (Textbox)mainComponent.FindComponent("ConsoleInput");
            outputLabel = (Memo)mainComponent.FindComponent("ConsoleOutput");

            inputText.KeyDown += new ComponentKeyEvent(inputText_KeyDown);
        }

        void inputText_KeyDown(Component sender, KeyEventArgs e)
        {
            switch(e.Key)
            {
                case Keys.Enter:
                    AddLine(">" + sender.Text);
                    sender.Text = "";
                    break;
            }
        }

        public void AddLine(string value)
        {
            if(outputLabel.Text == string.Empty)
            { outputLabel.Text = value;}
            else
            { outputLabel.Text += ("\r\n" + value); }
            outputLabel.SelectEnd = outputLabel.SelectStart = outputLabel.Text.Length;
        }
    }
}
